package com.youfang.sixthmedia.message;

import java.util.LinkedList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.youfang.sixthmedia.controller.LogoController;
import com.youfang.sixthmedia.message.model.Building;
import com.youfang.sixthmedia.net.Response;

/**
 * 获取新楼房列表请求
 * 
 * @author Administrator
 * 
 */
public class GethousesResponse extends Response {

	protected List<Building> buildings = new LinkedList<Building>();

	@Override
	protected void decodeBody(JSONObject bodyJSON) throws Exception {

		JSONArray arr = bodyJSON.getJSONArray("building");
		for (int i = 0; i < arr.length(); i++) {
			JSONObject o = arr.getJSONObject(i);

			this.buildings.add(processItem(o));

		}

	}

	protected Building processItem(JSONObject o) throws Exception {
		Building b = new Building();
		b.id = o.getString("id");
		b.buildingname = o.getString("buildingname");
		b.logo = o.getString("logo");
		b.readnum = getString(o, "readnum");
		b.price = o.getString("price");
		b.address = o.getString("address");
		b.privilegeid = getInt(o, "privilegeid");

		b.longitude = getDouble(o, "longitude");
		b.latitude = getDouble(o, "latitude");

		b.grouponbydev = getInt(o, "grouponbydev");

		b.pricedesc = getString(o, "pricedesc");
		b.advisername = getString(o, "advisername");
		b.developername = getString(o, "developername");

		b.buildingtype = getString(o, "buildingtype");
		b.region = getString(o, "region");

		// 内部标示的ID
		b.innerID = Long.parseLong(b.id);
		b.logoBitmap = LogoController.Cache.getFromCache(b);

		return b;
	}

	public List<Building> getBuildings() {
		return buildings;
	}

	public void setBuildings(List<Building> buildings) {
		this.buildings = buildings;
	}

}
